package com.mxw.算法之美.a7二分查找;

public class a04查找第一个大于等于给定值的元素 {


    static int left_ge_bound(int[] nums, int target) {
        int left = 0, right = nums.length - 1;

        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] >= target) {
                // 取左边，舍弃右边，看看左边还有没有目标值
                if ((mid == 0) || (nums[mid - 1] < target)) {
                    return mid;
                } else {
                    right = mid - 1;
                }
            } else {
                // 取右边，舍弃左边
                left = mid + 1;
            }
        }
        return -1;
    }

}
